<?php
include_once $_SERVER['DOCUMENT_ROOT']."/class/sqlclass.php";
include_once $_SERVER['DOCUMENT_ROOT'].'/db/mysql.php';
include_once $_SERVER['DOCUMENT_ROOT'].'/class/userClass.php';

class model {

    private $sql;
    
    public  $user;
    public  $dbErr = 0;

    function __construct() {
        $conf = $this->configuredb();
        $this->sql = new sql_db($conf->dbhost,$conf->dbuser,$conf->dbpasswd,$conf->dbmain);
        if (!$this->sql->db_connect_id) $this->dbErr = true;

        //$this->sql->sql_query("set names utf8");

        $this->dbErr = $this->checkDBconnection();
        $this->user = & new user();
    }

    function configuredb() {
        $file = $_SERVER['DOCUMENT_ROOT']."/conf/configDb.xml";
        $xmlfile = file_get_contents($file);
        $xml = new SimpleXMLElement($xmlfile);
        $output->dbhost = $xml->DataBaseConfig->host;
        $output->dbuser = $xml->DataBaseConfig->user;
        $output->dbpasswd = $xml->DataBaseConfig->passwd;
        $output->dbmain = $xml->DataBaseConfig->main;

        return $output;
    }

    function checkDBconnection() {
        $err = $this->sql->sql_error();
        return $err['code'];
    }



    
}
?>
